package com.example.redissontest.controller;

import com.example.redissontest.annotation.RepeatSubmitToken;
import com.example.redissontest.service.MyService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @author rfuser
 */
@RestController
@RequestMapping("/my")
public class MyController {

    @Resource
    private MyService myService;


    @RequestMapping("/manuallyAcquireLock")
    public void manuallyAcquireLock() throws Exception {
        myService.manuallyAcquireLock();
    }


    @RequestMapping("/aopLock")
    //@RepeatSubmitToken(leaseTime = 3,waitTime = 1, timeUnit = TimeUnit.SECONDS, value = "aopLock")
    public void aopLock() throws Exception {
        myService.doSomething();
    }

    @RequestMapping("/myHello")
    @RepeatSubmitToken(leaseTime = 3,waitTime = 1, timeUnit = TimeUnit.SECONDS, value = "aopLock")
    public String hello(@RequestParam String name) throws Exception {
        return myService.hello(name);
    }

}
